<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/20
 * Time: 15:06
 */
namespace  App\Models\Forms;

use App\Helper;
use App\Lib\Sdk\Spider\PddSpider;
use App\Models\Group;
use App\Models\IReadable;
use Encore\Admin\Widgets\Form;

/**
 * Class TbSpiderConfig
 * @package App\Models\Forms
*/
class TbSpiderConfig extends Form implements IReadable
{

    public $title = "淘宝";


    public function attributeLabels()
    {
        return [
            'cat' => [
                'type' => 'select',
                'label' => '采集分类',
                'options' => TaobaoDefiner::CATEGORIES,
                'required' => true
            ],
            'send_type' => [
                'type' => 'radio',
                'label' => '发送类型',
                'options' => TaobaoDefiner::SEND_TYPE,
                'required' => true
            ],
     /*       'send_group' => [
                'label' => '发送群组',
                'type' => 'select',
                'options' => Group::getByUid(),
            ],*/
            'coupon' => [
                'label' => '优惠券',
                'type' => 'radio',
                'options' => [
                    '无优惠券',
                    '有优惠券'
                ],
                'value' => 0,
                'visible' => true
            ],
            'presale' => [
                'label' => '营销活动',
                'type' => 'checkbox',
                'options' => TaobaoDefiner::YX,
                'required' => false
            ],
            'sort' => [
                'label' => '排序方式',
                'type' => 'select',
                'options' => TaobaoDefiner::SORT_TYPE,
                'required' => true,
                'value' => "tk_rate_des"
            ],
            'start_tk_rate' => [
                'label' => '最低佣金比例(%)',
                'type' => 'rate',
                'required' => true,
                'value' =>  0
            ],
         /*   'min_sale' => [
                'label' => '最低销量',
                'type' => 'integer',
                'required' => true,
                'value' =>  0
            ],*/
            'end_price' => [
                'label' => '折扣价范围上限',
                'type' => 'integer',
                'place_holder' => "折扣价范围不高于此数据",
                'required' => true,
                'value' => 0
            ],
            'page' => [
                'label' => '采集页数(每页50条数据)',
                'type' => 'integer',
                'place_holder' => "每页50条数据",
                'value' => 1
            ],
            "para" => [
                'type' => 'text',
                'label' => '关键词',
                'place_holder' => "请输入采集关键词，如 袜子"
            ],
        ];
    }

    public function form() {
        Helper::loadForm($this);
    }

    public function getAttribute($field)
    {
        // TODO: Implement getAttribute() method.
    }

    public function load($data)
    {
         foreach ($this->attributeLabels() as $key => $_) {
             if (isset($data[$key])) {
                 $this->$key = $data[$key];
             } else {
                 $this->$key = null;
             }
         }
    }




}
